<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
		<link rel="stylesheet" href="../../../css/common.css" media="all">
	</head>
	<body>
		<div class="layui-fluid">
			<div class="layui-row layui-col-space15">
				<div class="layui-col-md12">
					<div class="layui-card test-table-operate-btn ">
						<!--<div class="layui-card-header">
							<span class="marign_right10">会员：</span>
							<button class="layui-btn layui-btn-danger layui-btn-sm .layui-btn" data-type="del">删除</button>
							<button class="layui-btn layui-btn-normal layui-btn-sm" data-type='add' id="add">充值</button>
						</div>-->
						
						
						<div class="layui-card-body">
							<ul class="layui-tab-title" style="margin-bottom: 20px">
								<li class="layui-this" id="all_status">全部</li>
								<li id="tobepaid_status">待支付</li>
								<li id="paid_status">已支付</li>
							</ul>
							<!-- 搜索 -->
							<form class="layui-form search" id="form" onsubmit="return false" action="##">
								<div class="layui-inline search_inline">
									<label class="layui-form-label">订单号：</label>
									<div class="layui-input-inline">
										<input class="layui-input" lay-verify="" placeholder="订单号" name="orderid" autocomplete="off">
									</div>
								</div>
								<div class="layui-inline search_inline">
									<label class="layui-form-label">商户订单号：</label>
									<div class="layui-input-inline">
										<input class="layui-input" lay-verify="" placeholder="商户订单号" name="order_id" autocomplete="off">
									</div>
								</div>
								<div class="layui-inline search_inline">
									<label class="layui-form-label">支付方式：</label>
									<div class="layui-input-inline">
										<select name="payment" class="payment"></select>
									</div>
								</div>
								<!-- <div class="layui-inline search_inline">
									<label class="layui-form-label">支付状态：</label>
									<div class="layui-input-inline">
										<select name="status" class="collections_record"></select>
									</div>
								</div> -->
								<div class="layui-inline search_inline">
									<label class="layui-form-label">会员编号：</label>
									<div class="layui-input-inline">
										<input class="layui-input" lay-verify="" placeholder="会员编号" name="member_id" autocomplete="off">
									</div>
								</div>
								<div class="layui-inline search_inline">
									<label class="layui-form-label">授权应用编号：</label>
									<div class="layui-input-inline">
										<input class="layui-input" lay-verify="" placeholder="授权应用编号" name="auth_app_id" autocomplete="off">
									</div>
								</div>
								<div class="layui-inline search_inline">
									<label class="layui-form-label">推荐人：</label>
									<div class="layui-input-inline">
										<input class="layui-input" lay-verify="" placeholder="编号/名称" name="recommend" autocomplete="off">
									</div>
								</div>
								<div class="layui-inline search_inline">
									<label class="layui-form-label">直推：</label>
									<div class="layui-input-inline">
										<input class="layui-input" lay-verify="" placeholder="编号/名称" name="direct_id" autocomplete="off">
									</div>
								</div>
								<div class="layui-inline search_inline">
									<label class="layui-form-label">间推：</label>
									<div class="layui-input-inline">
										<input class="layui-input" lay-verify="" placeholder="编号/名称" name="indirect_id" autocomplete="off">
									</div>
								</div>
								<div class="layui-inline search_inline">
									<label class="layui-form-label">团队：</label>
									<div class="layui-input-inline">
										<input class="layui-input" lay-verify="" placeholder="编号/名称" name="team_id" autocomplete="off">
									</div>
								</div>
								<div class="layui-inline search_inline">
									<label class="layui-form-label">合伙人：</label>
									<div class="layui-input-inline">
										<input class="layui-input" lay-verify="" placeholder="编号/名称" name="copartner_id" autocomplete="off">
									</div>
								</div>
								<div class="layui-inline search_inline">
									<label class="layui-form-label">时间段：</label>
									<div class="layui-input-inline">
										<input class="layui-input" style="width:300px" id="choosetime" placeholder="时间段" autocomplete="off">
										<input class="layui-input" type="hidden" name="s_dates" placeholder="" autocomplete="off">
										<input class="layui-input" type="hidden" name="e_dates" placeholder="" autocomplete="off">
									</div>
								</div>
								<button class="layui-btn search_inline" lay-submit="" lay-filter="search" data-type="reload">搜索</button>
								<button class="layui-btn layui-btn-primary search_inline" type="reset">重置</button>
							</form>
							<!-- 搜索 -->

							<table class="layui-hide" id="test-table-operate" lay-filter="test-table-operate"></table>
							<script type="text/html" id="zizeng">
								{{d.LAY_TABLE_INDEX+1}}
							</script>
							<script type="text/html" id="test-table-operate-barDemo">
								<a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="detail">明细</a>
							</script>
						</div>
					</div>
				</div>
			</div>
		</div>
		<script type="text/html" id="test-table-operate-recommend">
			<div style="text-align: left;">
				<font style="color: #000;">({{d.recommendid?d.recommendid:''}})</font><font style="color: #000;">{{d.recommendname?d.recommendname:''}}</font><br>
			</div>
		</script>
		<script type="text/html" id="test-table-operate-direct">
			<div style="text-align: left;">
				<font style="color: #000;">({{d.directid?d.directid:''}})</font><font style="color: #000;">{{d.directname?d.directname:''}}</font><br>
			</div>
		</script>
		<script type="text/html" id="test-table-operate-indirect">
			<div style="text-align: left;">
				<font style="color: #000;">({{d.indirectid?d.indirectid:''}})</font><font style="color: #000;">{{d.indirectname?d.indirectname:''}}</font><br>
			</div>
		</script>
		<script type="text/html" id="test-table-operate-team">
			<div style="text-align: left;">
				<font style="color: #000;">({{d.teamid?d.teamid:''}})</font><font style="color: #000;">{{d.teamname?d.teamname:''}}</font><br>
			</div>
		</script>
		<script type="text/html" id="test-table-operate-copartner">
			<div style="text-align: left;">
				<font style="color: #000;">({{d.copartnerid?d.copartnerid:''}})</font><font style="color: #000;">{{d.copartnername?d.copartnername:''}}</font><br>
			</div>
		</script>
		<script src="../../../layuiadmin/layui/layui.js"></script>
		<script src="../../../js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../../js/common.js"></script>
		<script>
			layui.config({
				base: '../../../layuiadmin/' //静态资源所在路径
			}).extend({
				index: 'lib/index' //主入口模块
			}).use(['index', 'table', 'laydate','form'], function() {
				var table = layui.table,
					$ = layui.$,
					form = layui.form,
					laydate = layui.laydate,
					admin = layui.admin;

				var _data = {}
				orders_vip_status_show('option');
				accoun_type_show('option');
				collections_record_show('option');
				payment_show('option');
				// tab 点击
				$('#all_status').click(() => {
					_data.status = ''
					initdata()
				})
				$('#tobepaid_status').click(() => {
					_data.status = 1
					initdata()
				})
				$('#paid_status').click(() => {
					_data.status = 2
					initdata()
				})
				
				function initdata() {
					table.render({
						elem: '#test-table-operate',
						url: server.collections_record_query,
						height: height_105,
						cellMinWidth: cellMinWidth,
						limit: limit,
						limits: limits,
						totalRow: true, //开启合计行
						defaultToolbar: [  'exports', {
							title: '提示' //标题
							, layEvent: 'LAYTABLE_TIPS' //事件名，用于 toolbar 事件中使用
							, icon: 'layui-icon-tips' //图标类名
						}],
						toolbar: true,
						cols: [
							[{
								width: 50,
								field: 'zizeng',
								title: '#',
								fixed: 'left',
								templet: '#zizeng'
							}, 
							{
								width: 80,
								align: 'center',
								toolbar: '#test-table-operate-barDemo',
								title: '操作',
								fixed: 'left',
								totalRowText: '合计',
							},{
								field: 'memberid',
								width: 100,
								title: '会员编号'
							},{
								field: 'name',
								width: 90,
								title: '会员昵称'
							},{
								field: 'orderid',
								width: 185,
								title: '订单编号'
							},{
							field: 'order_id',
								width: 218,
								title: '商户订单号'
							},{
								field: 'payment', 
								width: 90,
								title: '支付方式',
								templet: function(d) {
									if(d.payment == 0) {
										return '<span class="text_red_color">' + payment_show(1,d.payment) + '</span>'
									} else if(d.payment == 1){
										return '<span class="text_greed_color">' + payment_show(1,d.payment) + '</span>'
									} else if(d.payment == 2){
										return '<span class="text_blue_color">' + payment_show(1,d.payment) + '</span>'
									} else if(d.payment == 3){
										return '<span class="text_gold_color">' + payment_show(1,d.payment) + '</span>'
									} else {
										return '<span class="text_yellow_color">' + payment_show(1,d.payment) + '</span>'
									}
								}
							},
							{
								field: 'auth_app_id',
								width: 160,
								title: '授权应用编号'
							},
							{
								field: 'seller_id',
								width: 160,
								title: '卖家编号'
							},
							{
								field: 'buyer_id',
								width: 160,
								title: '买家编号'
							},
							{
								field: 'status', 
								width: 90,
								title: '支付状态',
								templet: function(d) {
									if(d.status == 1) {
										return '<span class="text_red_color">' + collections_record_show(1,d.status) + '</span>'
									} else {
										return '<span class="text_blue_color">' + collections_record_show(1,d.status) + '</span>'
										

									}
								}
							},
							{
								field: 'accountid', 
								width: 90,
								title: '账户名称',
								templet: function(d) {
									return '<span class="text_red_color">' + accoun_type_show(1,d.accountid) + '</span>'
								},
							},{
								field: 'amount', 
								width: 100,
								title: '订单金额',
								totalRow: true,
							}, {
								field: 'pay_price', 
								width: 100,
								title: '支付金额',
								totalRow: true,
							},{
								field: 'refund_amount', 
								width: 100,
								title: '退款金额',
								totalRow: true,
							},{
								field: 'is_refund_money', 
								width: 100,
								title: '可退款金额',
								totalRow: true
								// templet: function(d) {
								// 	return (d.pay_price-d.refund_amount)
								// }
							},
//							{
//								field: 'fee', 
//								title: '金额',
//							}, 
							{
								field: 'pay_time', 
								width: 170,
								title: '支付时间',
							},{
								field: 'recommend',
								width: 150,
								title: '推荐人',
								toolbar: '#test-table-operate-recommend'
							},{
								field: 'direct',
								width: 150,
								title: '直推',
								toolbar: '#test-table-operate-direct'
							},{
								field: 'indirect',
								width: 150,
								title: '间推',
								toolbar: '#test-table-operate-indirect'
							},{
								field: 'team',
								width: 150,
								title: '团队',
								toolbar: '#test-table-operate-team'
							}, {
								field: 'copartner',
								width: 150,
								title: '合伙人',
								toolbar: '#test-table-operate-copartner'
							}, {
								field: 'add_by',
								width: 90,
								title: '创建人',
							}, {
								field: 'addtime', 
								width: 170,
								title: '创建时间',
							}, {
								field: 'edit_by', 
								width: 90,
								title: '更新人',
							}, {
								field: 'edittime', 
								width: 170,
								title: '更新时间',
							}]
						],
						page: true,
						where: _data,
						request: {
							pageName: 'page',
							limitName: 'size',
						},
						parseData: function(res) { //将原始数据解析成 table 组件所规定的数据
						let vals=res.collections_record.data
						vals.map((item,index)=>{
							item.is_refund_money=Number(item.pay_price-item.refund_amount)
						})
							return {
								"code": res.code, //解析接口状态
								"msg": res.msg, //解析提示文本
								"count": res.collections_record.pager.total, //解析数据长度
								"data": vals //解析数据列表
							};
						}
					});
				}
				// _data.s_dates = getNextDate(0)+' 00:00:00';
				// _data.e_dates = getNextDate(0)+' 23:59:59';
				// $('input[name=s_dates]').val(_data.s_dates);
				// $('input[name=e_dates]').val(_data.e_dates);
				laydate.render({
					elem: '#choosetime',
					type: 'date',
					range: true,
					// value:_data.s_dates+' - '+_data.e_dates,
					done: function(value, date) {
						console.log(getNextDate(0));
						$('input[name=s_dates]').val(value.split(' - ')[0]+' 00:00:00');
						$('input[name=e_dates]').val(value.split(' - ')[1]+' 23:59:59');
					}
				});
				
				initdata();

				//监听搜索
				form.verify({
					memberid: function(value, item) { //value：表单的值、item：表单的DOM对象
						if (!value) {
							return '姓名不能为空';
						}
					}
				});

				//监听搜索
				form.on('submit(search)', function(data) {
					_data = data.field
					initdata();
					return false;
				});

				$("button[type=reset]").on("click", function() {
					_data = {}
					$('input[name=s_dates]').val('')
					$('input[name=e_dates]').val('')
					initdata();
					document.getElementById("form").reset();
				});

				//监听表格复选框选择
				table.on('checkbox(test-table-operate)', function(obj) {
					console.log(obj)
				});


				//监听工具条
				table.on('tool(test-table-operate)', function(obj) {
					var data = obj.data;
					if (obj.event === 'detail') {
						layer.open({
							type: 2,
							title: '详情',
							shadeClose: false,
							shade: 0.5,
							area: ['85%', '85%'],
							content: 'model/detail_list.html?memberid=' + data.memberid,
							end: function() {
							}
						});
					} 
				});

				var $ = layui.$,
					active = {
						del: function() { //获取选中数据
							var checkStatus = table.checkStatus('test-table-operate'),
								data = JSON.stringify(checkStatus.data);
							var id= "";
							for(var i = 0; i < checkStatus.data.length; i++) {
								id += checkStatus.data[i].id;
								if(i != checkStatus.data.length - 1) {
									id += ",";
								}
							}
							if(checkStatus.data.length == 0) {
								layer.msg('至少选择一条')
							} else {
								layer.confirm('确定要删除所选的' + checkStatus.data.length + '条数据？', function() {
									$.ajax({
										url: server.collections_record_delete,
										type: 'post',
										dataType: 'json',
										data: "id=" + id,
										success: function(data) {
											if(data.code == '0') {
												layer.msg('删除成功');
												initdata();
											} else {
												layer.msg('删除失败');
												initdata();
											}
										},
										'error': function() {
											layer.msg('系统错误');
											initdata();
										}
									})
								});
							}
						},
						getCheckData: function() { //获取选中数据
							var checkStatus = table.checkStatus('test-table-operate'),
								data = checkStatus.data;
							layer.alert(JSON.stringify(data));
						},
						getCheckLength: function() { //获取选中数目
							var checkStatus = table.checkStatus('test-table-operate'),
								data = checkStatus.data;
							layer.msg('选中了：' + data.length + ' 个');
						},
						isAll: function() { //验证是否全选
							var checkStatus = table.checkStatus('test-table-operate');
							layer.msg(checkStatus.isAll ? '全选' : '未全选')
						}
					};

				$('.test-table-operate-btn .layui-btn').on('click', function() {
					var type = $(this).data('type');
					active[type] ? active[type].call(this) : '';
				});
				$('#add').on('click', function() {
					layer.open({
						type: 2,
						title: '添加',
						shadeClose: true,
						shade: 0.5,
						maxmin: true, //开启最大化最小化按钮
						area: ['750px', '700px'],
						content: 'model/edit_add.html',
						end: function() {

						}
					});
				});
			});
		function getNextDate(day) {
		　　var dd = new Date();
		　　dd.setDate(dd.getDate() + day);
		　　var y = dd.getFullYear();
		　　var m = dd.getMonth() + 1 < 10 ? "0" + (dd.getMonth() + 1) : dd.getMonth() + 1;
		　　var d = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate();
		　　return y + "-" + m + "-" + d;
		};
		</script>
	</body>
</html>
